package com.wcs.spring.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wcs.spring.entity.ClassInfo;
import com.wcs.spring.service.ClassInfoService;
import com.wcs.spring.util.PageUtil;

@Controller
@RequestMapping(value = "mgt/classInfo")
public class ClassInfoController {
	@Resource(name = "classInfoService")
	private ClassInfoService classInfoService;

	@RequestMapping(value = "classInfoList")
	public ModelAndView classInfoList(ClassInfo classInfo, PageUtil pageUtil, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		List<ClassInfo> list = this.classInfoService.queryClassInfoList(classInfo, pageUtil);

		map.put("classInfoList", list);
		return new ModelAndView("mgt/classInfo/classInfo_list", map);
	}

	@RequestMapping(value = "toClassInfoSave")
	public ModelAndView toClassInfoSave(HttpServletResponse response) throws Exception {
		return new ModelAndView("mgt/classInfo/classInfo_add");
	}

	@RequestMapping(value = "toClassInfoUpdate")
	public ModelAndView toClassInfoUpdate(Integer id, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		ClassInfo classInfo = classInfoService.queryClassInfoById(id);
		map.put("classInfo", classInfo);
		return new ModelAndView("mgt/classInfo/classInfo_add", map);
	}

	@RequestMapping(value = "toClassInfoShow")
	public @ResponseBody
	ClassInfo toClassInfoShow(Integer id, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		ClassInfo classInfo = classInfoService.queryClassInfoById(id);
		// map.put("classInfo", classInfo);
		// return new ModelAndView("mgt/classInfo/classInfo_show", map);
		return classInfo;
	}

	@RequestMapping(value = "classInfoSave")
	public ModelAndView classInfoSave(ClassInfo classInfo, HttpServletResponse response) throws Exception {
		Date date = new Date();
		classInfo.setCreateTime(date);
		classInfo.setUpdateTime(date);
		classInfo.setCreateUser("admin");
		classInfo.setUpdateUser("admin");
		classInfoService.addClassInfo(classInfo);
		return new ModelAndView("redirect:/mgt/classInfo/classInfoList.do");
	}

	@RequestMapping(value = "classInfoUpdate")
	public ModelAndView classInfoUpdate(ClassInfo classInfo, HttpServletResponse response) throws Exception {
		classInfo.setUpdateTime(new Date());
		classInfo.setUpdateUser("hexuan");
		classInfoService.updateClassInfo(classInfo);
		return new ModelAndView("redirect:/mgt/classInfo/classInfoList.do");
	}

	@RequestMapping(value = "classInfoDelete")
	public ModelAndView classInfoDelete(ClassInfo classInfo, HttpServletResponse response) throws Exception {
		classInfoService.delClassInfo(classInfo);
		return new ModelAndView("redirect:/mgt/classInfo/classInfoList.do");
	}

	@RequestMapping(value = "nowWeekClass")
	public ModelAndView nowWeekClass(HttpServletResponse response) throws Exception {
		return new ModelAndView("mgt/classInfo/nowWeekClass");
	}

	@RequestMapping(value = "otherWeekClass")
	public ModelAndView otherWeekClass(HttpServletResponse response) throws Exception {
		return new ModelAndView("mgt/classInfo/otherWeekClass");
	}

}
